#include "subject.h"

#include "observer.h"

using namespace std;
using namespace spacedefender;

Subject::Subject(void)
{
}

Subject::~Subject(void)
{
	_observers.clear();
}

void Subject::Attach(Observer* newObserver)
{
	//if the observer already is listening don't add it again
	for(list<Observer*>::const_iterator it = _observers.begin(); it != _observers.end(); it++)
	{
		if((*it) == newObserver)
			return;
	}
	
	_observers.push_back(newObserver);
}

void Subject::Detach(Observer* existingObserver)
{
	_observers.remove(existingObserver);
}

void Subject::Notify()
{	
	for(list<Observer*>::iterator it = _observers.begin(); it != _observers.end();it++)
	{
		(*it)->Notification(this);
	}
}
